package cn.labbook.bluetooth.util;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

import java.util.Random;

public class MessageTestUtil {
    /*
    pom.xml
    <dependency>
      <groupId>com.aliyun</groupId>
      <artifactId>aliyun-java-sdk-core</artifactId>
      <version>4.0.3</version>
    </dependency>
    */
        public static void main(String[] args) {

            Random random = new Random();
            StringBuilder str = new StringBuilder();
            for (int i = 0; i < 6; i++) {
                str.append(random.nextInt(10));
            }
            int i = Integer.parseInt(str.toString());


            DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI9s79vleJpwII", "uKUA0vWPhgvj28THpJC1o67g82NVwF");
            IAcsClient client = new DefaultAcsClient(profile);

            CommonRequest request = new CommonRequest();
            //request.setProtocol(ProtocolType.HTTPS);
            request.setMethod(MethodType.POST);
            request.setDomain("dysmsapi.aliyuncs.com");
            request.setVersion("2017-05-25");
            request.setAction("SendSms");
            request.putQueryParameter("RegionId", "cn-hangzhou");
            request.putQueryParameter("PhoneNumbers", "17826800659");
            request.putQueryParameter("SignName", "佐小二");
            request.putQueryParameter("TemplateCode", "SMS_163431432");
            request.putQueryParameter("TemplateParam", "{\"code\":\""+i+"\"}");

            try {
                CommonResponse response = client.getCommonResponse(request);
                System.out.println(response.getData());
            } catch (ServerException e) {
                e.printStackTrace();
            } catch (ClientException e) {
                e.printStackTrace();
            }

        }
    }
